package com.lemon.smartsafetynew.ui.activity.message;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafetynew.ui.fragment.hidden.SafeHiddenProcessTabOneFragment;
import com.lemon.smartsafetynew.ui.fragment.hidden.SafeHiddenProcessTabTwoFragment;
import com.lemon.smartsafetynew.ui.fragment.message.MessageListFragment;

import butterknife.Bind;

/**
 * 消息通知列表
 * Created by Andrew on 2018/4/19.
 */
public class MessageListActivity extends SwipeBackActivity {

    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.viewPager)
    ViewPager viewPager;

    private MessageInfoViewpagerAdapter viewpagerAdapter;

    @Override
    protected void initTitle() {
        this.setBarTitle(R.string.menu_message_title);
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(MessageListActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_viewpage_tab_layout;
    }

    @Override
    protected void initViews() {
        super.initViews();

        // ======= 该变指示栏的长度 =======
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                setIndicator(tabLayout, 10, 10); //左右各缩进5dp
            }
        });

        initViewPager();
    }

    /**
     * 初始化ViewPager
     */
    private void initViewPager() {
        viewpagerAdapter = new MessageInfoViewpagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(viewpagerAdapter);
        //viewPager.setPageTransformer(true, new ZoomOutSlideTransformer());
        tabLayout.setupWithViewPager(viewPager);
    }

    private class MessageInfoViewpagerAdapter extends FragmentStatePagerAdapter {

        public MessageInfoViewpagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return MessageListFragment.newInstance("1");
                case 1:
                    return MessageListFragment.newInstance("0");
                default:
                    return MessageListFragment.newInstance("1");
            }
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return getString(R.string.menu_message_not_read);
                case 1:
                    return getString(R.string.menu_message_has_read);
            }
            return getString(R.string.menu_message_not_read);
        }

    }
}
